package com.heyqing.topic.CountNodes_0222;

import java.util.Objects;

/**
 * ClassName:CountNodes
 * Package:com.heyqing.topic.CountNodes_0222
 * Description:
 *
 * @Date:2024/9/23
 * @Author:Heyqing
 */
public class CountNodes {

    private int nodeNum = 0;
    public int countNodes(TreeNode root) {
        achieveFunc(root);
        return nodeNum;
    }

    private void achieveFunc(TreeNode root) {
        if (Objects.isNull(root)) return;
        nodeNum++;
        achieveFunc(root.left);
        achieveFunc(root.right);
    }
}
